package b4.view.component.smithy
{
	import b4.config.BasicObjConfig;
	import b4.config.Config;
	import b4.config.EquipConfig;
	import b4.model.vo.player.*;
	import b4.view.component.basic.TitledPanel;
	import b4.view.component.events.ItemClickEvent;
	import flash.events.MouseEvent;
	
	import org.aswing.JButton;
	import org.aswing.JPanel;
	import org.aswing.JTextField;
	import org.aswing.SoftBoxLayout;
	public class  EquipBreak extends BaseSmithy
	{
		private var generatedBoxArr:Array;
		public var payPane :TitledPanel;
		private var payTxt:JTextField;
		public var succPane :TitledPanel;
		public var failAppend:TitledPanel;
		public var breakButton:JButton;
		public var equipBox_1:BoxObj;
		public var equipBox_2:BoxObj;
		public var equipBox_3:BoxObj;
		public var equipBox_4:BoxObj;
		public var greenBox:BoxObj;
		public var blueBox:BoxObj;
		public var yellowBox:BoxObj;
		public var purpleBox:BoxObj;
		
		public function EquipBreak()
		{
			super("请放入要分解的装备","分解说明");
			tryToLoadRs = {1:"请放入装备", 2: "白色装备无法分解"};
			equipBox_1 = new BoxObj("装备", 1, 1028);
			equipBox_2 = new BoxObj("装备", 1, 1028);
			equipBox_3 = new BoxObj("装备", 1, 1028);
			equipBox_4 = new BoxObj("装备", 1, 1028);
			leftTopContent.setLayout(new SoftBoxLayout(SoftBoxLayout.Y_AXIS))
			var leftTopContentNorth:JPanel = new JPanel();
			leftTopContentNorth.setPreferredHeight(55);
			var leftTopContentCenter:JPanel = new JPanel();
			leftTopContentCenter.setPreferredHeight(55);
			leftTopContent.appendAll(leftTopContentNorth,leftTopContentCenter);
			leftTopContentNorth.appendAll(equipBox_1,equipBox_2,equipBox_3,equipBox_4);
			
			boxArr.push(equipBox_1,equipBox_2,equipBox_3,equipBox_4);
//			绿蓝黄紫
			greenBox = new BoxObj("绿色", 10009, 10009);
			blueBox = new BoxObj("蓝色", 10010, 10010);
			yellowBox = new BoxObj("黄色",10011, 10011);
			purpleBox = new BoxObj("紫色", 10012, 10012);
			leftTopContentCenter.appendAll(greenBox, blueBox, yellowBox, purpleBox);
			boxArr.push(greenBox, blueBox, yellowBox, purpleBox);
			payPane = new TitledPanel("费用（铜币）", 70, 50);
			payTxt = new JTextField();
			payTxt.setPreferredHeight(20);
			payTxt.setPreferredWidth(75);
			payPane.append(payTxt);
			leftTopContentCenter.append(payPane);
			breakButton = new JButton("开始分解");
			leftBottom.append(breakButton);
			equipBox_1.addEventListener(ItemClickEvent.LOAD_ITEM_OFF, onLoadItemOff);
			equipBox_2.addEventListener(ItemClickEvent.LOAD_ITEM_OFF, onLoadItemOff);
			equipBox_3.addEventListener(ItemClickEvent.LOAD_ITEM_OFF, onLoadItemOff);
			equipBox_4.addEventListener(ItemClickEvent.LOAD_ITEM_OFF, onLoadItemOff);
			greenBox.addEventListener(ItemClickEvent.LOAD_ITEM_OFF, onLoadItemOff);
			blueBox.addEventListener(ItemClickEvent.LOAD_ITEM_OFF, onLoadItemOff);
			yellowBox.addEventListener(ItemClickEvent.LOAD_ITEM_OFF, onLoadItemOff);
			purpleBox.addEventListener(ItemClickEvent.LOAD_ITEM_OFF, onLoadItemOff);
		}
		
		private function onLoadItemOff(e:ItemClickEvent):void
		{
			var boxObj :BoxObj = e.currentTarget as BoxObj;
			var tabLoadOffEvent:ItemClickEvent = new ItemClickEvent(ItemClickEvent.TAB_LOAD_ITEM_OFF)
			dispatchEvent(tabLoadOffEvent);
			refreshPayTxt();						
		}
		
		override public function tryToLoadItem(obj:BasicObj):int
		{
			var basicObjConfig:BasicObjConfig = Config.objConfigs[obj.index];		
			var objType:int = basicObjConfig.type;
			if(objType != BasicObjConfig.TYPE_EQUIP)
				return 1;
			var equipConfig:EquipConfig = basicObjConfig as EquipConfig;
			var equip:Equip = obj as Equip;
			if(equip.quality == EquipConfig.WHRITE_INDEX)
				return 2;
			return 0;
		}
		
		override public function loadItem(obj:BasicObj):BoxObj
		{
			var returnBox:BoxObj;
			returnBox = super.loadItem(obj);
			refreshPayTxt();
			return returnBox;
		}
		
		private function refreshPayTxt():void
		{	 
			var payNum:int = 0;
			for (var tempStr:String in boxArr)
			{
				var boxObj :BoxObj = boxArr[tempStr] as BoxObj;
				if (boxObj.hasObj)
				{
					payNum += 15;
				}
			}
			payTxt.setText(String(payNum));
		}
		
	}
}
